Skip to content

Document HostingStartup incompatibility and migration to modern hosting patterns for .NET Aspire #4187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Aug 11, 2025

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 4, 2025

This PR addresses the incompatibility between HostingStartup and .NET Aspire integrations by providing comprehensive migration guidance from the legacy hosting pattern to the modern IHostApplicationBuilder approach.

The Problem

.NET Aspire integrations require IHostApplicationBuilder, but HostingStartup only provides access to the older IWebHostBuilder. This fundamental API difference means:

  • Aspire integration methods like AddNpgsqlDbContext() are not available
  • Modern hosting features (service discovery, built-in telemetry, health checks) can't be configured
  • Applications using HostingStartup miss out on .NET Aspire's observability and resilience patterns

The Solution

The documentation emphasizes migration as the necessary path forward rather than workarounds, recognizing that HostingStartup represents decade-old technology that predates modern .NET hosting patterns.

Key Content

  • Clear explanation of why the incompatibility exists at the API level
  • Before/after examples showing the transition from IWebHostBuilder to IHostApplicationBuilder
  • Conceptual guidance on the hosting model changes introduced in ASP.NET Core 6.0+
  • Migration resources linking to official ASP.NET Core migration guides and David Fowl's migration patterns

Example Migration

Before (HostingStartup - incompatible):

public class MyDatabaseStartup : IHostingStartup
{
    public void Configure(IWebHostBuilder builder) // ❌ Wrong builder type
    {
        builder.ConfigureServices(services => { ... });
    }
}

After (Modern hosting - compatible):

var builder = WebApplication.CreateBuilder(args);
builder.AddServiceDefaults();                    // ✅ Aspire integration
builder.AddNpgsqlDbContext<MyDbContext>("postgres"); // ✅ Works correctly

This approach guides developers toward modern .NET patterns while ensuring they can leverage .NET Aspire's full feature set including service discovery, telemetry, and resilience capabilities.

Fixes #3861.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.


Internal previews

📄 File 🔗 Preview link
docs/fundamentals/integrations-overview.md docs/fundamentals/integrations-overview
docs/toc.yml docs/toc
docs/troubleshooting/hosting-startup-not-supported.md docs/troubleshooting/hosting-startup-not-supported

@Copilot Copilot AI changed the title [WIP] When using Hosting startup I'm unable to configure most if any Aspire services Document HostingStartup incompatibility with .NET Aspire integrations Aug 4, 2025
@Copilot Copilot AI requested a review from IEvangelist August 4, 2025 20:47
Copilot finished work on behalf of IEvangelist August 4, 2025 20:47
…wline, move code snippets to external files, fix ordered list format

Co-authored-by: IEvangelist <[email protected]>
Copilot finished work on behalf of IEvangelist August 6, 2025 21:02
@Copilot Copilot AI requested a review from IEvangelist August 6, 2025 21:02
@Copilot Copilot AI requested a review from IEvangelist August 7, 2025 18:32
Copilot finished work on behalf of IEvangelist August 7, 2025 18:32
@Copilot Copilot AI changed the title Document HostingStartup incompatibility with .NET Aspire integrations Document HostingStartup incompatibility and migration to modern hosting patterns for .NET Aspire Aug 8, 2025
@Copilot Copilot AI requested a review from IEvangelist August 8, 2025 13:29
Copilot finished work on behalf of IEvangelist August 8, 2025 13:29
@Copilot Copilot AI requested a review from IEvangelist August 11, 2025 13:31
Copy link
Member

@IEvangelist IEvangelist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maddymontaquila - thoughts on this article?

@Copilot Copilot AI requested a review from IEvangelist August 11, 2025 17:44
Copilot finished work on behalf of IEvangelist August 11, 2025 17:44
Copilot finished work on behalf of adegeo August 11, 2025 17:49
@Copilot Copilot AI requested a review from adegeo August 11, 2025 17:49
@Copilot Copilot AI requested a review from adegeo August 11, 2025 17:57
Copilot finished work on behalf of adegeo August 11, 2025 17:57
Copilot finished work on behalf of adegeo August 11, 2025 18:00
@Copilot Copilot AI requested a review from adegeo August 11, 2025 20:47
Copilot finished work on behalf of adegeo August 11, 2025 20:47
@IEvangelist IEvangelist enabled auto-merge (squash) August 11, 2025 23:20
@IEvangelist IEvangelist merged commit 5b2305c into main Aug 11, 2025
9 checks passed
@IEvangelist IEvangelist deleted the copilot/fix-3861 branch August 11, 2025 23:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

When using Hosting startup I'm unable to configure most if any Aspire services
3 participants